﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="my_givelist.aspx.cs" Inherits="my_givelist" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>我的赠刊名录</title>
    <link href="./css/ecrm03.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="./jquery/126/jquery-1.2.6.js"></script>	<script type="text/javascript" src="./jquery/datepicker/ui.core.js"></script>	<script type="text/javascript" src="./jquery/datepicker/ui.datepicker.js"></script>	<script type="text/javascript" src="./jquery/datepicker/i18n/ui.datepicker-zh-CN.js"></script>    <link rel="stylesheet" type="text/css" href="./jquery/datepicker/datepicker.css" />
    <style type="text/css">
	    .table_apply{
            background-color:#669999;
	    }
	    .table_update{
            background-color:#cccc99;
	    }
	    .table_cancel{
            background-color:#cccccc;
	    }
	    .tr_apply{
            background-color:#669999;
	    }
	    .tr_update{
            background-color:#cccc99;
	    }
	    .tr_cancel{
            background-color:#cccccc;
	    }
	    .td_apply{
	        font-size: 10pt; 
	        color: white; 
	        background-color: #669999;
	        cursor: hand;
	    }
	    .td_update{
	        font-size: 10pt; 
	        color: white; 
	        background-color: #cccc99;
	        cursor: hand;
	    }
	    .td_cancel{
	        font-size: 10pt; 
	        color: white; 
	        background-color: #cccccc;
	        cursor: hand;
	    }
        .odd {background-color:#f5f5f5;}
        .even {background-color:#ffffff;}
    </style>
    <script type="text/javascript">
	    function zmag_show(uid,opt)
	    {
            var PointX;
            var PointY;
            
            $("#linkmanid").val(uid);
            $("#myopt").val(opt);
            
            width=300;
            height=200;
            if(navigator.appName.indexOf('Microsoft')!=-1)
            {
                var oEvent=window.event;
                PointX=oEvent.clientX + document.body.scrollLeft - document.body.clientLeft;
                PointY=oEvent.clientY + document.body.scrollTop - document.body.clientTop;
                
                xx=document.body.clientWidth;
                //xx=screen.width;
                if((xx-PointX)<(width+5))
                {
                    PointX=PointX-(width-(xx-PointX))-30;
                }
                
                yy=document.body.scrollHeight;
                if((yy-PointY)<(height))
                {
                    PointY=PointY-(height-(yy-PointY))-50;
                }
                
            }
            else
            {
                var oEvent=arguments[0];
                PointX=oEvent.pageX;
                PointY=oEvent.pageY;
            }

            $("#"+uid).removeClass('odd');
            $("#"+uid).removeClass('even');
            $("#"+uid).removeClass('tr_apply');
            $("#"+uid).removeClass('tr_update');
            $("#"+uid).removeClass('tr_cancel');
            $("#zmag_table").removeClass('table_apply');
            $("#zmag_table").removeClass('table_update');
            $("#zmag_table").removeClass('table_cancel');
            
            switch (opt)
            {
                case '1':
                    $("#"+uid).addClass('tr_apply');
                    $("#zmag_table").addClass('table_apply');
                    zmag_clear();
                    break;
                case '2':
                    $("#"+uid).addClass('tr_update');
                    $("#zmag_table").addClass('table_update');
                    zmag_get();
                    break;
                case '3':
                    $("#"+uid).addClass('tr_cancel');
                    $("#zmag_table").addClass('table_cancel');
                    zmag_get();
                    break;
            }
            
            document.getElementById('zmag').style.left=PointX;
            document.getElementById('zmag').style.top=PointY;
            document.getElementById('zmag').style.display='';
	    }
	    
	    function zmag_clear()
	    {
	        $('#zmag_lvl').attr('value','');
	        $('#zmag_type').attr('value','');
	        $('#zmag_qchb').attr('checked','');
	        $('#zmag_dgjy').attr('checked','');
	        $('#zmag_qty').val('1');
	        $('#zmag_bdate').val('');
	        $('#zmag_edate').val('');
	        $('#zmag_expl').val('');
	    }
	    
	    function zmag_get()
	    {
	        var url='my_givelist01.ashx?linkmanid='+$('#linkmanid').val()+'&_='+(new Date()).getTime();	        $.getJSON(url,	            function(giveman)	            {	                $('#zmag_lvl').attr("value",giveman['givelvl']);	                $('#zmag_type').attr("value",giveman['givetype']);	                var mags=new String(giveman['givemag']);	                if(mags.indexOf('汽车画报')!=-1)	                {	                    $('#zmag_qchb').attr('checked',true);	                }	                else	                {	                    $('#zmag_qchb').attr('checked',false);	                }	                if(mags.indexOf('动感驾驭')!=-1)	                {	                    $('#zmag_dgjy').attr('checked',true);	                }	                else	                {	                    $('#zmag_dgjy').attr('checked',false);	                }	                $("#zmag_qty").val(giveman['giveqty']);	                if(giveman['givebdate']!='1949-01-01')	                {	                    $("#zmag_bdate").val(giveman['givebdate']);	                }	                else	                {	                    $("#zmag_bdate").val('');	                }	                if(giveman['giveedate']!='1949-01-01')	                {	                    $("#zmag_edate").val(giveman['giveedate']);	                }	                else	                {	                    $("#zmag_edate").val('');	                }	                $("#zmag_expl").val(giveman['giveexpl']);	            }	        );	    }
	    
	    function chk()
	    {
	        if($('#zmag_lvl').val()=='')
	        {
	            alert('请您选择赠阅级别！');
	            return false;
	        }

	        if($('#zmag_type').val()=='')
	        {
	            alert('请您选择赠阅类型！');
	            return false;
	        }
            var mags='';            if($("#zmag_qchb").attr('checked'))            {                mags+=$('#zmag_qchb').attr('value');            }            if($("#zmag_dgjy").attr('checked'))            {                mags+=$('#zmag_dgjy').attr('value');            }            if(mags=='')            {	            alert('请您至少选择一种期刊！');
	            return false;
            }
	        if($('#zmag_qty').val()=='')
	        {
	            alert('数量要填写！');
	            return false;
	        }

	        if($('#zmag_bdate').val()=='')
	        {
	            alert('日期要填写！');
	            return false;
	        }

	        if($('#zmag_edate').val()=='')
	        {
	            alert('日期要填写！');
	            return false;
	        }

	        if($('#zmag_expl').val()=='')
	        {
	            alert('赠阅理由不能空，要充分！');
	            return false;
	        }
	        
	        var gbdate=new String($('#zmag_bdate').val())
	        var mybdate=new Date();
	        var byear=gbdate.substr(0,4);
	        var bmonth=gbdate.substr(5,2)-1;
	        var bday=gbdate.substr(8,2);
	        
	        mybdate.setFullYear(byear,bmonth,bday);
	        //alert(mybdate.getFullYear()+'-'+mybdate.getMonth()+'-'+mybdate.getDate());
	        
	        var gedate=new String($('#zmag_edate').val());
	        var myedate=new Date();
	        var eyear=gedate.substr(0,4);
	        var emonth=gedate.substr(5,2)-1;
	        var eday=gedate.substr(8,2);
	        myedate.setFullYear(eyear,emonth,eday);
	        
	        if(myedate<mybdate)
	        {
	            alert('终止日期小于开始日期，请重新选择！');
	            return false;
	        }
	        
	        if($('#zmag_lvl').val()=='普通')
	        {
	            if(((myedate-mybdate)/86400000)>92)
	            {
	                alert('普通级别的赠阅最多3个月，到期后可以续申请！');
	                return false;
	            }
            }
	        
	        if($('#zmag_lvl').val()=='VIP')
	        {
	            if(((myedate-mybdate)/86400000)>365)
	            {
	                alert('VIP级别的赠阅最多12个月，到期后可以续申请！');
	                return false;
	            }
            }
	        
	        return true;
	    }
	    
	    //保存至数据库
	    function zmag_apply()
	    {
            if(chk()==false) return false;                        var mags='';            if($("#zmag_qchb").attr('checked'))            {                mags+=$('#zmag_qchb').attr('value');            }            if($("#zmag_dgjy").attr('checked'))            {                mags+=$('#zmag_dgjy').attr('value');            }                        var urlstring='my_givelist02.ashx';            var urldata='myuid='+$('#myuid').val()+'&linkmanid='+$('#linkmanid').val()+'&opt='+$('#myopt').val()+'&givelvl='+escape($('#zmag_lvl').val())+'&givetype='+escape($('#zmag_type').val())+'&givemag='+escape(mags)+'&giveqty='+$('#zmag_qty').val()+'&giveexpl='+escape($('#zmag_expl').val())+'&givebdate='+$('#zmag_bdate').val()+'&giveedate='+$('#zmag_edate').val()+'&_='+(new Date()).getTime();            $.ajax({                url:urlstring,                type:'post',                dataType:'html',                data:urldata,                beforeSend:function()                {                },                success: function(msg)                {                    //更新                    var manid=$('#linkmanid').val();                                        var opt=$('#myopt').val();                    switch (opt)
                    {
                        case '1':
                            $("#"+manid+"_1").empty().append("<font color='#669999'>新申请</font>");                            break;
                        case '2':
                            $("#"+manid+"_1").empty().append("<font color='#cccc99'>续申请</font>");                            break;
                        case '3':
                            $("#"+manid+"_1").empty().append("<font color='#cccccc'>已取消</font>");                            break;
                    }
                                                            $("#"+manid+"_2").empty().append($("#zmag_expl").val());                                        var myshrdate=new String($("#zmag_bdate").val());                    myshrdate=myshrdate.substring(2,10);                    $("#"+manid+"_3").empty().append(myshrdate);                                        var myshrdate2=new String($("#zmag_edate").val());                    myshrdate2=myshrdate2.substring(2,10);                    $("#"+manid+"_4").empty().append(myshrdate2);                                        zmag_hide();                },	            error:function()	            {	                alert('保存失败！');	            }            });	    }
	    
	    function zmag_hide()
	    {
            document.getElementById('zmag').style.display='none';

            $('#manlist tbody tr:odd').addClass('odd');
            $('#manlist tbody tr:even').addClass('even');
	    }

        $(document).ready(function(){
            $('#manlist thead tr').addClass('odd');
            $('#manlist tbody tr:odd').addClass('odd');
            $('#manlist tbody tr:even').addClass('even');
            $('#zmag_bdate').datepicker();
            $('#zmag_edate').datepicker();
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width =950px align="center">
            <tr>
                <td style="width: 15px; height: 47px; background-color: #ffffff" valign="middle"></td>
                
                <td  style="background-color:#0075B0; height :47px; width: 950px;" valign="middle">
                    <DIV style="text-align: left ; font-family:Arial; text-align:left;" >
                        <span style=" font-family:'Arial Black'; color:#FFFFFF; font-size:16pt;">
                            <b>&nbsp;&nbsp;&nbsp;&nbsp;MagSpace
                                
                            </b>
                        </span>
                     </DIV>
                 </td>
                 
                 <td style="background-color:#0075B0; height :47px; width: 190px;" valign="middle" align="right">
                    <DIV style="text-align: left ; font-family:Arial; text-align:left;" >
                        <span style=" font-family:'Arial Black'; color:#FFFFFF; font-size:16pt;">
                             <span class="pl"><asp:Literal ID="userstatus1" runat="server"></asp:Literal>&nbsp;&nbsp;<asp:Literal ID="userstatus2" runat="server"></asp:Literal></span>
                             </span>
                     </DIV>
                 </td>
                 
                <td style="width: 15px; height: 47px; background-color: #ffffff" valign="middle"></td>
                    
            </tr>
        </table>
        <br />
        
        <table width=900 align="center">
            <tr>
                <td style="text-align:center" id="tab01" class="titletab02"><a href="index.aspx">首页</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="tab03" class="titletab02"><a href="my_ecrm.aspx">我的名片夹</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="Td1" class="titletab01"><a href="my_givelist.aspx">我的赠刊名录</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="Td2" class="titletab02"><a href="my_plan.aspx">我的周计划</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="Td3" class="titletab02"><a href="easybbs.aspx">员工交流区</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="Td4" class="titletab02"><a href="employee2.aspx">员工联系表</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="Td6" class="titletab02"><a href="vote/vote.aspx">投票</a></td>
                <td class="titletab03">&nbsp;</td>
                <td style="text-align:center" id="Td5" class="titletab02"><a href="webdisk/default.aspx">网盘</a></td>
                <td class="titletab04">&nbsp;</td>
            </tr>
        </table>
        <table width=900 border="0" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td style="font-weight: bold; font-size: 10pt;">
                    <%--<div id="nav"><a href="index.aspx"><span>首页</span></a><a href="my_ecrm.aspx"><span>我的名片夹</span></a><a class="now" href="my_givelist.aspx"><span>我的赠刊名录&nbsp;&nbsp;</span></a><a href="my_plan.aspx"><span>我的周计划</span></a><a href="easybbs.aspx"><span>员工交流区</span></a><a href="employee2.aspx"><span>员工联系表</span></a><a href="webdisk/default.aspx"><span>网盘</span></a></div>
                    <div class="clear"></div><div id="status"><div id="subnav"></div><span class="pl"><asp:Literal ID="userstatus1" runat="server"></asp:Literal><asp:Literal ID="userstatus2" runat="server"></asp:Literal></span></div>--%>
                    <br />
                    <table align="center" width="95%" border="0">
                        <tr>
                            <td style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid">
                                <div id="linkmanlist" runat="server"></div>
                            </td>
                        </tr>
                    </table>
                    <br />
                    <div style="border-bottom: darkgray 1px solid;"></div>
                    <span class="bottomfont">SEEC&copy;2008-2009 汽车中国</span>
                </td>
            </tr>
        </table>
    </div>
    <div id="myhidediv" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; VISIBILITY: hidden; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px; HEIGHT: 1px"><asp:TextBox id="myuid" runat="server"></asp:TextBox><asp:TextBox id="linkmanid" runat="server"></asp:TextBox><asp:TextBox id="myopt" runat="server"></asp:TextBox></div>
    <!--隐藏的层-->
    <div id="zmag" style="width: 300px;height:200px; position: absolute;display:none;">
        <div style="BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; BORDER-LEFT: gray 1px solid; BORDER-BOTTOM: gray 1px solid; ">
            <table id="zmag_table" border="1" cellpadding="2" cellspacing="0" style='BORDER-COLLAPSE: collapse' bordercolor="#cfdfff" width="100%">
                <tr height="28">
                    <td>&nbsp;赠阅级别</td>
                    <td>&nbsp;<select id="zmag_lvl">
                            <option value="" selected>请选择...</option>
                            <option value="VIP">VIP</option>
                            <option value="普通">普通</option>
                        </select>
                    </td>
                </tr>
                <tr height="28">
                    <td>&nbsp;赠阅类型</td>
                    <td>&nbsp;<select id="zmag_type">
                            <option value="" selected>请选择...</option>
                            <option value="客户">客户</option>
                            <option value="朋友">朋友</option>
                            <option value="亲属">亲属</option>
                            <option value="其它">其它</option>
                        </select>
                    </td>
                </tr>
                <tr height="28">
                    <td>&nbsp;所赠刊物</td>
                    <td>&nbsp;<input id="zmag_qchb" type="checkbox" value="汽车画报" title="汽车画报" />汽车画报&nbsp;<input id="zmag_dgjy" type="checkbox" value="动感驾驭" title="动感驾驭" />动感驾驭&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="zmag_qty" type="text" style="width: 18px" value="1" />本</td>
                </tr>
                <tr height="28">
                    <td>&nbsp;赠阅时间</td>
                    <td>&nbsp;<input id="zmag_bdate" type="text" style="width: 90px" />至<input id="zmag_edate" type="text" style="width: 90px" /></td>
                </tr>
                <tr>
                    <td>&nbsp;赠阅理由<br />&nbsp;(要充分)</td>
                    <td>&nbsp;<textarea id="zmag_expl" style="width: 200px; height: 60px"></textarea></td>
                </tr>
                <tr height="28">
                    <td colspan="2" align="center"><input id="btn_hide" type="button" onclick="zmag_hide()" value="关闭" style="width: 50px" /><input id="btn_save" type="button" value="保存" onclick="zmag_apply()" style="width: 50px" /></td>
                </tr>
            </table>
        </div>
    </div>
    </form>
</body>
</html>
